package com.hey.baseapplication.api;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Hey on 16/12/15.
 */

public class UserAgentInterceptor implements Interceptor {
    private static final String USER_AGENT_HEADER_NAME = "User-Agent";

    private String value;
    public UserAgentInterceptor(String value){

        this.value=value;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        final Request originalRequest = chain.request();

        final Request requestWithUserAgent = originalRequest.newBuilder()
                //移除先前默认的UA
                .removeHeader(USER_AGENT_HEADER_NAME)
                //设置UA
                .addHeader(USER_AGENT_HEADER_NAME, value)

                .build();
        return chain.proceed(requestWithUserAgent);
    }
}
